<?php
/**
 * Created by PhpStorm.
 * User: 554665488
 * Date: 2018-7-10
 * Time: 21:39
 * @description:
 * @Author: yfl
 * @QQ 554665488
 */
//go(function() {
//    go(function () {
////        co::sleep(3.0);
//        go(function () {
////            co::sleep(2.0);
//            echo "co[3] end\n";
//        });
//        echo "co[2] end\n";
//    });
//
////    co::sleep(1.0);
//    echo "co[1] end\n";
//});
//use Swoole\Coroutine as co;
//$id = go(function(){
//    $id = co::getUid();
//    echo "start coro $id\n";
//    co::suspend();
//    echo "resume coro $id @1\n";
//    co::suspend();
//    echo "resume coro $id @2\n";
//});
//echo "start to resume $id @1\n";
//co::resume($id);
//echo "start to resume $id @2\n";
//co::resume($id);
//echo "main\n";
use Swoole\Coroutine as co;
$chan = new co\Channel(1);
co::create(function () use ($chan) {
    for($i = 0; $i < 100000; $i++) {
        co::sleep(1.0);
        $chan->push(['rand' => rand(1000, 9999), 'index' => $i]);
        $chan->push(['rand' => 'qqq', 'index' => $i]);
//        echo "$i\n";
    }
});
co::create(function () use ($chan) {
    while(1) {
        $data = $chan->pop();
        $data2 = $chan->pop();
        var_dump($data);
        var_dump('2==',$data2);
    }
});
swoole_event::wait();